/**
 * Copyright (c) 2014, 2017, Oracle and/or its affiliates.
 * The Universal Permissive License (UPL), Version 1.0
 */
"use strict";
/*
 Copyright 2013 jQuery Foundation and other contributors
 Released under the MIT license.
 http://jquery.org/license
*/
define(["ojs/ojcore","jquery","ojs/ojcomponentcore"],function(a,g){(function(){var b=0;a.Ra("oj.ojCollapsible",g.oj.baseComponent,{widgetEventPrefix:"oj",options:{expanded:!1,disabled:null,expandOn:"click",expandArea:"header",beforeExpand:null,expand:null,beforeCollapse:null,collapse:null,optionChange:null},_ComponentCreate:function(){this._super();this.element.addClass("oj-collapsible oj-component");this.tba();this.Of();this.Tj=!0;var a=this.element[0];this.NS({type:this.options.expanded?"ojexpand":
"ojcollapse",target:a,currentTarget:a,preventDefault:g.noop});this.Tj=void 0},ph:function(a,b,e){this.qh(b,e,{launcher:this.fD().first()})},Wra:function(){var a=this.options.expanded?"oj-collapsible-open-icon":"oj-collapsible-close-icon";(this.Ul()?g("\x3cspan\x3e"):g("\x3ca href\x3d'#'\x3e")).addClass("oj-component-icon oj-clickable-icon-nocontext oj-collapsible-header-icon "+a).attr("aria-labelledby",this.header.attr("id")).prependTo(this.header)},r6:function(){this.header.children(".oj-collapsible-header-icon").remove()},
_destroy:function(){this.wo();this.element.removeClass("oj-collapsible oj-component oj-expanded oj-collapsed oj-disabled");this.Ul()&&this.VS(this.header).removeAttr("tabIndex");this.header.removeClass("oj-collapsible-header").each(function(){/^oj-collapsible/.test(this.id)&&this.removeAttribute("id")});this.ZC().removeAttr("role").removeAttr("aria-controls").removeAttr("aria-expanded").removeAttr("aria-disabled");this.r6();this.content.css("display","").removeAttr("aria-hidden").removeAttr("tabIndex").removeClass("oj-component-content oj-collapsible-content").each(function(){/^oj-collapsible/.test(this.id)&&
this.removeAttribute("id")})},wo:function(){this.Nz();this.content&&(a.D.unwrap(this.content),this.Up=null)},Ul:function(){return this.element.hasClass("oj-disabled")},P7:function(){return"header"==this.options.expandArea?"\x3e .oj-collapsible-header":"\x3e .oj-collapsible-header \x3e .oj-collapsible-header-icon"},fD:function(){return this.header.find(".oj-collapsible-header-icon")},_setOption:function(a,b,e){"expanded"===a?b!==this.options.expanded&&this.JDa(b):"disabled"===a?(this.header.add(this.header.next()),
this.element.toggleClass("oj-disabled",!!b)):"expandOn"===a||"expandArea"===a?(this.Nz(),this._super(a,b,e),this.Bn()):this._super(a,b,e)},Tv:function(a){if(!a.altKey&&!a.ctrlKey){var b=g.ui.keyCode;switch(a.keyCode){case b.SPACE:case b.ENTER:this.mea(a)}}},refresh:function(){this._super();this.wo();this.tba();this.r6();this.Of()},tba:function(){this.header=this.element.children(":first-child").addClass("oj-collapsible-header");this.content=this.header.next().addClass("oj-collapsible-content oj-component-content");
this.content.wrap("\x3cdiv\x3e\x3c/div\x3e");this.Up=this.content.parent().addClass("oj-collapsible-wrapper");this.options.disabled&&this.element.addClass("oj-disabled");this.Ul()&&this.VS(this.header).attr("tabIndex",-1)},Of:function(){var a=this.header,d=this.content,e=this.options,f="oj-collapsible-"+(this.element.attr("id")||++b),g=a.attr("id"),k=d.attr("id");g||a.attr("id",f+"-header");k||(k=f+"-content",d.attr("id",k));this.Wra();a=this.ZC();a.attr("role","button").attr("aria-controls",k).attr("aria-expanded",
e.expanded);this.Ul()&&a.attr("aria-disabled","true");e.expanded?d.removeAttr("aria-hidden"):(this.Up.css({"max-height":0,"overflow-y":"hidden",display:"none"}),this.Up.css("max-height",0),d.attr("aria-hidden","true"));this.Bn()},JDa:function(a){a?this.expand(!0):this.collapse(!0)},Bn:function(){var b={keydown:this.Tv},d=this.options.expandOn;if(d){var e=this;g.each(d.split(" "),function(d,g){a.D.qN(g)&&(b[g]=e.mea)})}d=this.element.find(this.P7());this._on(d,b);this._on(this.Up,{transitionend:this.Sz,
webkitTransitionEnd:this.Sz,otransitionend:this.Sz,oTransitionEnd:this.Sz});this.Ul()||(this._on(this.element,{ojexpand:this.NS,ojcollapse:this.NS,ojfocus:this.l7,ojfocusout:this.l7}),this._focusable({element:this.fD(),applyHighlight:!0}),this.We(d),this.Gk(d))},Nz:function(){this._off(this.element.find(this.P7()));this.Up&&this._off(this.Up);this._off(this.element.add(this.content))},mea:function(a){this.Ul()||a.isDefaultPrevented()||(this.options.expanded?this.collapse(!0,a):this.expand(!0,a),a.preventDefault(),
a.stopPropagation(),this.fD().focus())},NS:function(b){if(!this.Ul()&&b.target===this.element[0]&&(this.Tj||!b.isDefaultPrevented())){var d=this.element,e=this.options,f=this.content,g=this.Up,k="ojexpand"===b.type;b.preventDefault();this.Tj?(e.expanded=k)?(d.removeClass("oj-collapsed"),d.addClass("oj-expanded"),a.Components.Mr(g[0])):(d.removeClass("oj-expanded"),d.addClass("oj-collapsed"),g.css("max-height",0),g.hide(),a.Components.ju(g[0])):(this.Qqa(k,b),g.rM=g.outerHeight(),k?(g.show(),setTimeout(function(){g.rM+=
f.outerHeight();g.addClass("oj-collapsible-transition").css({"max-height":g.rM});d.removeClass("oj-collapsed");d.addClass("oj-expanded");a.Components.Mr(g[0])},1)):(g.removeClass("oj-collapsible-transition"),g.css({"max-height":g.rM,"overflow-y":"hidden"}),setTimeout(function(){g.addClass("oj-collapsible-transition").css({"max-height":0});d.removeClass("oj-expanded");d.addClass("oj-collapsed");a.Components.ju(g[0])},10)));this.fD().toggleClass("oj-collapsible-open-icon",k).toggleClass("oj-collapsible-close-icon",
!k||!1).end();k?this.content.removeAttr("aria-hidden"):this.content.attr("aria-hidden","true");this.ZC().attr("aria-expanded",k)}},l7:function(a){if(this.Ul())return null;"ojfocusout"==a.type?(this.ZC().attr("tabIndex",-1),a.preventDefault(),a.stopPropagation()):"ojfocus"==a.type&&(this.ZC().attr("tabIndex",0).focus(),a.preventDefault(),a.stopPropagation())},ZC:function(){return this.VS(this.header).first()},VS:function(a){return this.Ul()?a.find("span"):a.find("a,:input")},expand:function(a,b){if(!this.Ul()){var e=
{header:this.header,content:this.content};a&&!1===this._trigger("beforeExpand",b,e)||this._trigger("expand",b,e)}},collapse:function(a,b){if(!this.Ul()){var e={header:this.header,content:this.content};a&&!1===this._trigger("beforeCollapse",b,e)||this._trigger("collapse",b,e)}},Sz:function(a){this.Ul()||("max-height"==(a.originalEvent?a.originalEvent.propertyName:null)&&(a.preventDefault(),a.stopPropagation()),this.options.expanded?this.Up.css({"max-height":9999,"overflow-y":""}):this.Up.hide(),this.Up.removeClass("oj-collapsible-transition"))},
Qqa:function(a,b){this.option("expanded",a,{_context:{originalEvent:b,Cd:!0,kb:!0}})},getNodeBySubId:function(a){if(null==a)return this.element?this.element[0]:null;switch(a.subId){case "oj-collapsible-content":return this.content[0];case "oj-collapsible-header":return this.header[0];case "oj-collapsible-disclosure":case "oj-collapsible-header-icon":return this.fD()[0]}return null},getSubIdByNode:function(a){for(var b=this.getNodeBySubId({subId:"oj-collapsible-disclosure"});a;){if(a===this.content[0])return{subId:"oj-collapsible-content"};
if(a===this.header[0])return{subId:"oj-collapsible-header"};if(a===b)return{subId:"oj-collapsible-disclosure"};a=a.parentElement}return null}})})();a.Components.Xa("ojCollapsible","baseComponent",{properties:{disabled:{type:"boolean"},expandArea:{type:"string"},expanded:{type:"boolean"},expandOn:{type:"string"}},methods:{collapse:{},expand:{},refresh:{}},extension:{_widgetName:"ojCollapsible"}});a.Components.register("oj-collapsible",a.Components.getMetadata("ojCollapsible"))});